package com.yihaodian.indices;

import java.io.File;
import java.io.FileNotFoundException;

import org.apache.solr.core.CoreContainer;

import com.yihaodian.api.common.Configs;
import com.yihaodian.api.search.SearchException;

public class SolrContainerFactory {
	static CoreContainer container = null;

	public static synchronized CoreContainer getCoreContainer() {
		if(container != null)
			return container;
		
		try {
			String solrHome = System.getProperty("solr.home");
			if (solrHome == null) {
				solrHome = Configs.getSolrHome();
			}
			File f = new File(solrHome, "solr.xml");
			container = new CoreContainer(solrHome, f);

			return container;
		} catch (FileNotFoundException e) {
			throw new SearchException(e);
		}
	}
}
